import numpy as np
import pandas as pd

# s = pd.Series(list('ABCD'))
# s = pd.Series(['A', 'B', 'C', 'D'])
# s = pd.Series(['A', 'B', 'C', 'D'], index=['one', 'two', 'three', 'four'])
s = pd.Series(pd.date_range('2021-08-20', periods=7))
print(s)
print(s.dtype)


df = pd.DataFrame(np.random.randn(7, 4), columns=list('ABCD'), index=pd.Series(pd.date_range('2021-08-20', periods=7)))
print(df)
print('......................')
print(df['B'])
print(df.loc['2021-08-20':'2021-08-25'])
print(df.loc['2021-08-20':'2021-08-25', 'A'])
print(df.loc['2021-08-20':'2021-08-25', ['A', 'C']])

df2 = pd.DataFrame({
    'name': ['Gsm', 'Tom', '杰克'],
    'age': [40, 50, 60]
})
print(df2)
# loc[行, 列]
print(df2.loc[df2['age'] > 55])
print(df2.loc[~(df2['age'] > 55)])  # 取反
print(df2.loc[0, :])
print(df2.loc[0, 'name'])
print(df2.loc[0:2, 'name'])

print(df2['age'].isin([50, 60]))
print(df2.loc[df2['age'].isin([50, 60])])
print(df2.loc[df2['name'].isin(['Gsm', '杰克'])])
print(df2.loc[~df2['name'].isin(['Gsm', '杰克'])])

print(df2.iloc[0, 0])  # 取单元格值
print(df2.iloc[0:2, 0])
